package cn.edu.scau.cmi.zhangjunming.factory;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.zhangjunming.simpleFactoryMethod.domain.Meat;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class FactoryController implements Initializable{

	private static Stage stage = null;
	private static Scene scene = null;
	@FXML Button beefButton;
	@FXML Button porkButton;
	@FXML Button chickenButton;
	@FXML Button returnButton;
	@FXML TextArea board;
	BeefMeatFactory beefFactory;
	PorkMeatFactory porkFactory;
	ChickenMeatFactory chickenFactory;
	
	public FactoryController() {
		// TODO 自动生成的构造函数存根
		beefFactory = new BeefMeatFactory();
		porkFactory = new PorkMeatFactory();
		chickenFactory = new ChickenMeatFactory();
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO 自动生成的方法存根
		
	}
	
	static void createScene() {
		if(scene==null) {
			try {
				URL url = new FactoryController().getClass().getResource("Factory.fxml");
				Parent root = FXMLLoader.load(url);
				scene = new Scene(root);
				
			}catch(IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static Stage getStage() {
		return stage;
	}
	
	public static void setStage(Stage stage) {
		FactoryController.stage = stage;
	}
	
	@FXML private void get_beef() {
		Meat meat = beefFactory.getMeat();
		board.appendText(meat.cook()+"\n");
		
	}
	
	@FXML private void get_pork() {
		Meat meat = porkFactory.getMeat();
		board.appendText(meat.cook()+"\n");
	}
	
	@FXML private void get_chicken() {
		Meat meat = chickenFactory.getMeat();
		board.appendText(meat.cook()+"\n");
	}
	
	@FXML private void returnMain() {
		Stage stage = (Stage)returnButton.getScene().getWindow();
		stage.close();
	}
}




